#ifndef GFRIENDSLIST_H
#define GFRIENDSLIST_H

#include<QString>
#include<QList>
#include<QFile>
#include<QTextStream>
#include<QStringList>

#include<iostream>


using namespace std;

/*!	\brief This class container information for each user in the friend list.
 *	
 *	
 *	
 *	
 *	
*/
class GFriend : public QObject {
	Q_OBJECT
public:
	GFriend(QObject* parent, QString str, int lastindex);
	
	~GFriend();
	
	/*!	\brief Set the name of this user.
	*/
	void name(QString str);
	
	/*!	\brief Get the name of this user.
	*/
	QString name();
	
	/*!	\brief Clear the changed bit.
	*/
	void setChanged();
	
	/*!	\brief Get the index of this user in the master login array.
	*/
	int index();
	
	/*!	\brief Set the index of this user in the master login array.
	 *	
	 *	This does not effect the actual index value of this user in the master array.
	 *	This value is only kept for optimization so when the friend list is loaded
	 *	the actual position of the user in the master array will be located faster.
	*/
	void index(int i);
	
	/*!	\brief This function returns the last know status of a user.
	*/
	QString status();
	
	/*!	\brief This function sets the last known status of the user.
	 *
	 *@param str A string specifying the status of the user.
	*/
	void status(QString str);
	
protected:
	QString nam;		//username
	QString stat;		//user status
	bool initstat; //first status message is send to initialize the stat string
	int ind;				//user index in login array
	
public slots:
	void receiveStatusUpdate(QString str);
	
	
signals:
	void sendStatusUpdate(QString name, QString status);
	
};

/*!	\brief This class contains an array of GFriends.
 *	
 *	This class also saves and loads the list of GFriends.
*/
class GFriendsList : public QObject {
	Q_OBJECT
public:
	/*!	\brief Constructor that does not do much but call the parent constructor.
	 *
	 *	@param parent A pointer to the parent of this object.
	*/
	GFriendsList(QObject* parent);
	
	/*!	\brief Save the friends list.
	 *	
	 *	@param fn The name of the file to save the list to.
	*/
	void save(QString fn);
	
	/*!	\brief Load the friend list.
	 *	
	 *	@param fn The name of the file to load the list from.
	*/
	void load(QString fn);
	
	/*!	\brief Add a username to the friend list.
	 *	
	 *	@param name The name of the user to add to the list.
	*/
	GFriend* add(QString name);
	
	/*!	\brief Remove a username from the friend list.
	 *	
	 *	@param name The name of the user to remove from the list.
	*/
	void remove(QString name);
	
	
	void clear();
	
	/*!	\brief Get the list as a comma separate list of values.
	*/
	QString listCSV();
	
	/*!	\brief Check if the list changed since it was last saved.
	*/
	bool changed();
	
	/*!	\brief Set the changed bit to false.
	*/
	void setChanged();
	
	/*!	\brief Get the number of users in the list.
	*/
	int size();
	
	/*!	\brief Iterate through the list.
	 *	
	 *	@return Returns a pointer to the friend class that contains
	 *	data for the user in the array.
	*/
	GFriend* operator[](int i);
	
private:
	QList<GFriend*> l;
	bool c;
	
	
protected:
	
	
signals:
	/*!	\brief Forwards the status update from the GLogin thread to the
	 *	GUser thread instance.
	 *	
	 *	@param name The name of the user this status update is coming from.
	 *	@param status A string representing the status of the user.
	*/
	void forwardStatusSig(QString name, QString status);
	
	
public slots:
	/*!	\brief This is the slot that receives status updates from the GLogin
	 *	thread.
	 *	
	 *	This function then calls the forwardStatusSig function to forward the
	 *	status update to the GUser thread instance.
	 *	
	 *	@param name The name of the user this status update is coming from.
	 *	@param status A string representing the status of the user.
	*/
	void forwardStatus(QString name, QString status);
	
};


#endif // GFRIENDSLIST_H
